home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / boot / WBSP_Prefs.lha / WBStartup+Prefs / Source / WBStartup+Prefs.c < prev    next >
C/C++ Source or Header  |  2002-03-06  |  40KB  |  1,224 lines

  1. /*Requests:
  2.  
  3. sort by CX_PRIORITY
  4. Update the list by monitoring the 2 dirs
  5. */
  6.  
  7.  
  8. /*  WBStartup+Prefs.c */
  9.  
  10. #define VERSION   "3.0"
  11. #define DATENUM   __AMIGADATE__
  12. #define DATETEXT  "January 18, 2002"
  13. #define COPYRIGHT "Original copyright © 1996 John Hughes"
  14. #define AUTHOR    "Pavel Fedin"
  15.  
  16. //#define DEBUG 1
  17.  
  18. /*****************************************************************/
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22.  
  23. #include <clib/dos_protos.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <utility/tagitem.h>    /* TAG_DONE */
  28. #include <dos/exall.h>
  29. #include <clib/alib_protos.h>   /* List */
  30. #include <clib/exec_protos.h>   /* AllocVec() */
  31. #include <workbench/startup.h>
  32. #include <dos/dostags.h>         /* SYS_Asynch */
  33. #include <dos/exall.h>
  34. #include <intuition/imageclass.h>
  35. #include <dos/stdio.h>
  36. #include <libraries/gadtools.h>
  37. #include <libraries/mui.h>
  38. #include <MUI/NList_mcc.h>
  39. #include <MUI/NListview_mcc.h>
  40.  
  41. /* These add the function prototypes and the #pragmas which reduce the code size */
  42. #include <proto/dos.h>
  43. #include <proto/exec.h>
  44. #include <proto/intuition.h>
  45. #include <proto/icon.h>
  46. #include <proto/wb.h>
  47. #include <proto/commodities.h>
  48. //#include <proto/diskfont.h>
  49. //#include <proto/graphics.h>
  50. #include <proto/utility.h>
  51. #include <proto/wb.h>
  52. #include <proto/muimaster.h>
  53.  
  54. #include <math.h>
  55.  
  56. #include "CheckBoxListView.h"
  57. #include "WBStartup+Prefs.h"
  58. #include "GetStringWindow.h"
  59. #include "GetPriorityWindow.h"
  60. #include "ChooseGroupWindow.h"
  61. #include "CopyWindow.h"
  62. #include "WBStartupPlusPrefs_Cat.h"
  63.  
  64. //#define MWDEBUG 1
  65. //#include "sc:extras/memlib/memwatch.h"
  66.  
  67. char const version[]="\0$VER: WBStartup+Prefs "VERSION"\0";
  68.  
  69. #define PREFSFILE "ENVARC:WBStartup+"
  70.  
  71. #define OUTSIDEBORDER 10
  72. #define GADTEXTBORDERSUM 6
  73.  
  74. /*  ln_Type's  */
  75. #define EXECUTE  TRUE
  76. #define STORAGE  FALSE
  77.  
  78.  
  79. void GetFilenames(APTR memPool, char *directory, UBYTE type);
  80. struct WBSPNode *AddFileToList(APTR memPool, char *pathname, UBYTE type);
  81. void GetArguments(int argc, char **argv);
  82. void ProcessEvents(APTR groupPool);
  83. BOOL RenderGadgets(struct Gadget **glist, void *vi,
  84. struct Window *win, struct Gadget *my_gads[], struct List *list,
  85. struct Gadget *(*CreateGadgetsFunction)(struct Gadget **glistptr, void *vi, struct Window *win, struct Gadget *my_gads[], struct List *list));
  86.  
  87. void ShowRequester(STRPTR RequesterText);
  88. void RestoreTypes(void);
  89. void SaveChanges(void);
  90. BOOL ChangePriTooltype(char *filename, BYTE pri);
  91. void ShowWBIconRequester(struct WBSPNode *node,struct Screen *scr);
  92.  
  93. void SaveGroups(void);
  94. void ReadGroups(APTR memPool);
  95. void CreateGroup(char *groupname, APTR memPool);
  96. void SelectGroup(struct List *list);
  97. void DeleteGroup(APTR memPool);
  98. BOOL Finditem (char *name);
  99. void __asm __saveds ProcessAppMsg(register __a1 ULONG *argsptr);
  100.  
  101. BOOL InitGUI(void);
  102. void SortList(void);
  103.  
  104. BOOL ShowGroupsRequester(void);
  105. BOOL CopyFile(char *source,char *dest);
  106.  
  107.  
  108. struct IntuitionBase *IntuitionBase;
  109. struct Library *GadToolsBase;
  110. struct Library *CxBase, *IconBase;
  111. struct Library *ScreenNotifyBase;
  112. struct Library *WorkbenchBase;
  113. struct Library *DiskfontBase;
  114. struct GfxBase *GfxBase;
  115. struct Library *UtilityBase;
  116. struct Library *MUIMasterBase;
  117.  
  118. Object *appobj,*winobj,*lsobj,*saveobj,*cancelobj,*checkoffobj,*checkonobj;
  119. Object *pwinobj,*sliderobj;
  120. Object *swinobj,*strobj;
  121. Object *gwinobj,*glsobj,*gokobj,*gcancelobj;
  122.  
  123. struct WBStartupPrefs prefs;
  124.  
  125. /****************************************************************************************/
  126.  
  127. struct Hook LVDisplayHook={0,0,LVDisplay,0,0};
  128. struct Hook GLVDisplayHook={0,0,GLVDisplay,0,0};
  129. struct Hook LVCompareHook={0,0,LVCompare,0,0};
  130. struct Hook AppMsgHook={0,0,(HOOKFUNC)ProcessAppMsg,0,0};
  131.  
  132. /****************************************************************************************/
  133.  
  134. long __stack=16384;
  135.  
  136. main (int argc, char **argv)
  137. {
  138. //  struct List grouplist;
  139.   struct MsgPort *port;
  140.  
  141.   if (IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37))
  142.   {
  143.     if (CxBase = OpenLibrary("commodities.library", 37L))
  144.     {
  145.       if (IconBase = OpenLibrary("icon.library", 36L))
  146.       {
  147.         if (WorkbenchBase = OpenLibrary("workbench.library", 39L))
  148.         {
  149.                 if (UtilityBase = OpenLibrary("utility.library", 37L))
  150.                 {
  151.          if (MUIMasterBase = OpenLibrary("muimaster.library",11))
  152.          {
  153.                   if (prefs.filenamePool=CreatePool(MEMF_PUBLIC,31,31))  /* Node is 14 bytes, largest filename is 30 */
  154.                   {
  155.                     if (prefs.groupPool=CreatePool(MEMF_PUBLIC,31,31))  /* Node is 14 bytes, largest filename is 30 */
  156.                     {
  157.              if (InitGUI())
  158.              {
  159. //                      NewList(&grouplist);
  160.                       GetArguments(argc, argv);
  161.  
  162.                       if (prefs.EnabledDirLock=Lock(prefs.ExecutePath,ACCESS_READ))
  163.                       {
  164.                         if (prefs.DisabledDirLock=Lock(prefs.StoragePath,ACCESS_READ))
  165.                         {
  166.                           prefs.NumPrograms=0;
  167.                           GetFilenames(prefs.filenamePool,prefs.ExecutePath,EXECUTE);
  168.                           GetFilenames(prefs.filenamePool,prefs.StoragePath,STORAGE);
  169.  
  170.                           ReadGroups(prefs.groupPool);
  171.                           ProcessEvents(prefs.groupPool);
  172.  
  173.                           UnLock(prefs.DisabledDirLock);
  174.                         }
  175.                         else
  176.                           ShowRequester(GetString(STRCouldntLockDir));
  177.                         UnLock(prefs.EnabledDirLock);
  178.                       }
  179.                       else
  180.                         ShowRequester(GetString(STRCouldntLockDir));
  181.  
  182.                       /* If WBStartup+ is running and waiting for us to quit, send it a message */
  183.                       Forbid();
  184.                       if (port=FindPort("WBStartup+"))
  185.                       {
  186.                         struct Message msg;
  187.                         PutMsg(port,&msg);
  188.                       }
  189.                       Permit();
  190.  
  191.               MUI_DisposeObject(appobj);
  192.               MUI_DisposeObject(checkonobj);
  193.               MUI_DisposeObject(checkoffobj);
  194.              }
  195.                      DeletePool(prefs.groupPool);
  196.                     }
  197.                     DeletePool(prefs.filenamePool);
  198.                }
  199.                CloseLibrary(MUIMasterBase);
  200.                   }
  201.                   CloseLibrary(UtilityBase);
  202.                 }
  203.           CloseLibrary(WorkbenchBase);
  204.         }
  205.         else
  206.           ShowRequester(GetString(STRRequiredDosVer));
  207.         CloseLibrary(IconBase);
  208.       }
  209.       CloseLibrary(CxBase);
  210.     }
  211.     CloseLibrary((struct Library *)IntuitionBase);
  212.   }
  213.  
  214.   #ifdef DEBUG
  215.     printf("Exiting\n");
  216.   #endif
  217. }
  218.  
  219. BOOL InitGUI(void)
  220. {
  221.   ULONG TitleMark;
  222.   struct NewMenu MainNewMenu[25]=
  223.   {
  224.     { NM_TITLE, NULL/*"Project"*/,                0, 0, 0, 0, },
  225.     {   NM_ITEM,  NULL/*"Save"*/,               "S", 0, 0, (APTR)SAVE_MENU, },
  226.     {   NM_ITEM,  NM_BARLABEL,                 0, 0, 0, 0, },
  227.     {   NM_ITEM,  NULL/*"About..."*/,              "?", 0, 0, (APTR)ABOUT_MENU, },
  228.     {   NM_ITEM,  NM_BARLABEL,                 0, 0, 0, 0, },
  229.     {   NM_ITEM,  NULL/*"Quit"*/,               "Q", 0, 0, (APTR)QUIT_MENU, },
  230.     { NM_TITLE, NULL/*"Edit"*/,                   0, 0, 0, 0, },
  231.     {   NM_ITEM,  NULL/*"Restore"*/,            "R", 0, 0, (APTR)RESTORE_MENU, },
  232.     {   NM_ITEM,  NULL/*"Icon Window..."*/,     "I", 0, 0, (APTR)PROGRAMINFO_MENU, },
  233.     {   NM_ITEM,  NM_BARLABEL,                 0, 0, 0, 0, },
  234.     {   NM_ITEM,  NULL/*"Create Group..."*/,    "C", 0, 0, (APTR)CREATEGROUP_MENU, },
  235.     {   NM_ITEM,  NULL/*"Modify Group..."*/,    "M", 0, 0, (APTR)MODIFYGROUP_MENU, },
  236.     {   NM_ITEM,  NM_BARLABEL,                 0, 0, 0, 0, },
  237.     {   NM_ITEM,  NULL/*"Delete Group..."*/,    "D", 0, 0, (APTR)DELETEGROUP_MENU, },
  238.     { NM_TITLE, NULL/*"Sort"*/,                   0, 0, 0, 0, },
  239.     {   NM_ITEM,  NULL/*"Alphabetically"*/,     "Z", 0, 0, (APTR)SORTALPHABETICALLY_MENU, },
  240.     {   NM_ITEM,  NULL/*"Priority"*/,           "P", 0, 0, (APTR)SORTPRIORITY_MENU, },
  241.     { NM_TITLE, NULL/*"Select"*/,                 0, 0, 0, 0, },
  242.     {   NM_ITEM,  NULL/*"All"*/,                "A", 0, 0, (APTR)SELECTALL_MENU, },
  243.     {   NM_ITEM,  NULL/*"None"*/,               "N", 0, 0, (APTR)SELECTNONE_MENU, },
  244.     {   NM_ITEM,  NULL/*"Toggle"*/,             "T", 0, 0, (APTR)SELECTTOGGLE_MENU, },
  245.     {   NM_ITEM,  NM_BARLABEL,                 0, 0, 0, 0, },
  246.     {   NM_ITEM,  NULL/*"Group..."*/,           "G", 0, 0, (APTR)SELECTGROUP_MENU, },
  247.       { NM_END,   NULL,                          0, 0, 0, 0, },
  248.   };
  249.  
  250.   int count=0;
  251.  
  252.   /* Put strings in Menu */
  253.   MainNewMenu[count++].nm_Label = GetString(STRProjectMenu);
  254.   MainNewMenu[count++].nm_Label = GetString(STRSaveMenu);
  255.   MainNewMenu[count++].nm_Label = NM_BARLABEL;
  256.   MainNewMenu[count++].nm_Label = GetString(STRAboutMenu);
  257.   MainNewMenu[count++].nm_Label = NM_BARLABEL;
  258.   MainNewMenu[count++].nm_Label = GetString(STRQuitMenu);
  259.   MainNewMenu[count++].nm_Label = GetString(STREditMenu);
  260.   MainNewMenu[count++].nm_Label = GetString(STRRestoreMenu);
  261.   MainNewMenu[count++].nm_Label = GetString(STRIconWindowMenu);
  262.   MainNewMenu[count++].nm_Label = NM_BARLABEL;
  263.   MainNewMenu[count++].nm_Label = GetString(STRCreateGroupMenu);
  264.   MainNewMenu[count++].nm_Label = GetString(STRModifyGroupMenu);
  265.   MainNewMenu[count++].nm_Label = NM_BARLABEL;
  266.   MainNewMenu[count++].nm_Label = GetString(STRDeleteGroupMenu);
  267.   MainNewMenu[count++].nm_Label = GetString(STRSortMenu);
  268.   MainNewMenu[count++].nm_Label = GetString(STRAlphabeticallyMenu);
  269.   MainNewMenu[count++].nm_Label = GetString(STRPriorityMenu);
  270.   MainNewMenu[count++].nm_Label = GetString(STRSelectMenu);
  271.   MainNewMenu[count++].nm_Label = GetString(STRAllMenu);
  272.   MainNewMenu[count++].nm_Label = GetString(STRNoneMenu);
  273.   MainNewMenu[count++].nm_Label = GetString(STRToggleMenu);
  274.   MainNewMenu[count++].nm_Label = NM_BARLABEL;
  275.   MainNewMenu[count].nm_Label = GetString(STRGroupMenu);
  276.  
  277.   if (prefs.Alphabetize)
  278.       TitleMark=MUIV_NList_TitleMark_Down|1;
  279.   else
  280.       TitleMark=MUIV_NList_TitleMark_Down|2;
  281.  
  282.   //Create all needed objects
  283.   appobj=MUI_NewObject("Application.mui",MUIA_Application_Author,AUTHOR,
  284.                        MUIA_Application_Base,"WBSTARTUP+PREFS",
  285.                      MUIA_Application_Copyright,COPYRIGHT,
  286.                      MUIA_Application_Description,"WBStartup+ preferences editor",
  287.                      MUIA_Application_SingleTask,TRUE,
  288.                      MUIA_Application_Title,"WBStartup+Prefs",
  289.                      MUIA_Application_Version,version[1],
  290.                      MUIA_Application_Window,
  291.     winobj=MUI_NewObject("Window.mui",MUIA_Window_AppWindow,TRUE,
  292.                       MUIA_Window_ID,1,
  293.                       MUIA_Window_Title,"WBStartup+ Prefs",
  294.                       MUIA_Window_RootObject,
  295.         MUI_NewObject("Group.mui",MUIA_Group_Child,
  296.             MUI_NewObject("NListview.mcc",MUIA_CycleChain,TRUE,
  297.                               MUIA_NListview_NList,
  298.                 lsobj=MUI_NewObject("NList.mcc",MUIA_NList_Format,"BAR,BAR,",
  299.                                 MUIA_NList_Title,TRUE,
  300.                                 MUIA_NList_DisplayHook,&LVDisplayHook,
  301.                                 MUIA_NList_CompareHook,&LVCompareHook,
  302.                                 MUIA_NList_TitleMark,TitleMark,
  303.                 TAG_DONE),
  304.             TAG_DONE),
  305.                       MUIA_Group_Child,
  306.             MUI_NewObject("Group.mui",MUIA_Group_Horiz,TRUE,
  307.                           MUIA_Group_Child,
  308.                 saveobj=MUI_NewObject("Text.mui",MUIA_CycleChain,TRUE,
  309.                                  MUIA_Frame,MUIV_Frame_Button,
  310.                                  MUIA_Background,MUII_ButtonBack,
  311.                                      MUIA_InputMode,MUIV_InputMode_RelVerify,
  312.                                      MUIA_Text_Contents,GetString(STRSave),
  313.                                      MUIA_Text_PreParse,"\33c",
  314.                 TAG_DONE),
  315.                           MUIA_Group_Child,
  316.                 cancelobj=MUI_NewObject("Text.mui",MUIA_CycleChain,TRUE,
  317.                                    MUIA_Frame,MUIV_Frame_Button,
  318.                                    MUIA_Background,MUII_ButtonBack,
  319.                                    MUIA_InputMode,MUIV_InputMode_RelVerify,
  320.                                    MUIA_Text_Contents,GetString(STRCancel),
  321.                                    MUIA_Text_PreParse,"\33c",
  322.                 TAG_DONE),
  323.             TAG_DONE),
  324.         TAG_DONE),
  325.                     MUIA_Window_Menustrip,
  326.         MUI_MakeObject(MUIO_MenustripNM,&MainNewMenu,0),
  327.     TAG_DONE),
  328.                      MUIA_Application_Window,
  329.     gwinobj=MUI_NewObject("Window.mui",MUIA_Window_RefWindow,winobj,
  330.                        MUIA_Window_LeftEdge,MUIV_Window_LeftEdge_Centered,
  331.                        MUIA_Window_TopEdge,MUIV_Window_TopEdge_Centered,
  332.                        MUIA_Window_ID,2,
  333.                        MUIA_Window_RootObject,
  334.         MUI_NewObject("Group.mui",MUIA_Group_Child,
  335.             MUI_NewObject("NListview.mcc",MUIA_CycleChain,TRUE,
  336.                               MUIA_NListview_NList,
  337.                 glsobj=MUI_NewObject("NList.mcc",MUIA_NList_DisplayHook,&GLVDisplayHook,
  338.                 
  339.                 TAG_DONE),
  340.             TAG_DONE),
  341.                       MUIA_Group_Child,
  342.             MUI_NewObject("Group.mui",MUIA_Group_Horiz,TRUE,
  343.                           MUIA_Group_Child,
  344.                 gokobj=MUI_NewObject("Text.mui",MUIA_CycleChain,TRUE,
  345.                                 MUIA_Frame,MUIV_Frame_Button,
  346.                                 MUIA_Background,MUII_ButtonBack,
  347.                                     MUIA_InputMode,MUIV_InputMode_RelVerify,
  348.                                     MUIA_Text_Contents,GetString(STROk),
  349.                                     MUIA_Text_PreParse,"\33c",
  350.                 TAG_DONE),
  351.                           MUIA_Group_Child,
  352.                 gcancelobj=MUI_NewObject("Text.mui",MUIA_CycleChain,TRUE,
  353.                                     MUIA_Frame,MUIV_Frame_Button,
  354.                                     MUIA_Background,MUII_ButtonBack,
  355.                                     MUIA_InputMode,MUIV_InputMode_RelVerify,
  356.                                     MUIA_Text_Contents,GetString(STRCancel),
  357.                                     MUIA_Text_PreParse,"\33c",
  358.                 TAG_DONE),
  359.             TAG_DONE),
  360.         TAG_DONE),
  361.     TAG_DONE),
  362.   TAG_DONE);
  363.  
  364.   // If everything is OK, set up notifications and exit
  365.   if (appobj)
  366.   {
  367.       if (checkoffobj=MUI_NewObject("Image.mui",MUIA_Image_Spec,MUII_CheckMark,TAG_DONE))
  368.     {
  369.         if (checkonobj=MUI_NewObject("Image.mui",MUIA_Image_Spec,MUII_CheckMark,
  370.                              MUIA_Image_State,IDS_SELECTED,
  371.                              TAG_DONE))
  372.               {
  373.                   DoMethod(lsobj,MUIM_NList_UseImage,checkoffobj,1,0);
  374.                   DoMethod(lsobj,MUIM_NList_UseImage,checkonobj,2,0);
  375.                   DoMethod(lsobj,MUIM_Notify,MUIA_NList_TitleClick,1,appobj,2,MUIM_Application_ReturnID,9);
  376.                   DoMethod(lsobj,MUIM_Notify,MUIA_NList_TitleClick,2,appobj,2,MUIM_Application_ReturnID,10);
  377.                   DoMethod(winobj,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,appobj,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  378.                   DoMethod(cancelobj,MUIM_Notify,MUIA_Pressed,FALSE,appobj,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  379.                   DoMethod(saveobj,MUIM_Notify,MUIA_Pressed,FALSE,appobj,2,MUIM_Application_ReturnID,3);
  380.                   DoMethod(lsobj,MUIM_Notify,MUIA_NList_EntryClick,MUIV_EveryTime,appobj,2,MUIM_Application_ReturnID,1);
  381.                   DoMethod(appobj,MUIM_Notify,MUIA_Application_MenuAction,MUIV_EveryTime,appobj,2,MUIM_Application_ReturnID,2);
  382.                   DoMethod(winobj,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,winobj,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  383.                   DoMethod(gwinobj,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,appobj,2,MUIM_Application_ReturnID,7);
  384.                   DoMethod(gcancelobj,MUIM_Notify,MUIA_Pressed,FALSE,appobj,2,MUIM_Application_ReturnID,7);
  385.                   DoMethod(glsobj,MUIM_Notify,MUIA_NList_DoubleClick,MUIV_EveryTime,appobj,2,MUIM_Application_ReturnID,8);
  386.                   DoMethod(gokobj,MUIM_Notify,MUIA_Pressed,FALSE,appobj,2,MUIM_Application_ReturnID,8);
  387.                   return(TRUE);
  388.             }
  389.         MUI_DisposeObject(checkoffobj);
  390.     }
  391.     MUI_DisposeObject(appobj);
  392.   }
  393.   return(FALSE);
  394. }
  395.  
  396. /* GetFilesnames() is NOT the same function that is in "WBStartup+.c" */
  397. void GetFilenames(APTR memPool, char *directory, UBYTE type)
  398. {
  399.   struct ExAllControl *myexallctrl;  /* The ExAllControl structure */
  400.   struct ExAllData    *eadptr;       /* temp pointer to data structure */
  401.   BPTR mylock;                       /* Lock on the directory */
  402.   int more;                          /* Are there more entries ? */
  403.   struct ExAllData ExAllBuf[20];     /* hold the filenames and types */
  404.   char pathname[500];                /* path and filename of the icon */
  405.   char filename[32];                 /* parsed match string 2*length+2=22 */
  406.  
  407.  
  408.   if (mylock=Lock(directory,SHARED_LOCK))
  409.   {
  410.     if (myexallctrl=(struct ExAllControl *)AllocDosObjectTags(DOS_EXALLCONTROL,TAG_END))
  411.     {
  412.       myexallctrl->eac_LastKey = 0;
  413.       myexallctrl->eac_Entries = 0;
  414.       myexallctrl->eac_MatchString = NULL;
  415.       myexallctrl->eac_MatchFunc = NULL;
  416.  
  417.       do   /* go until more==0 */
  418.       {
  419.         more = ExAll(mylock, ExAllBuf, sizeof(ExAllBuf), ED_TYPE, myexallctrl);
  420.         if ((!more) && (IoErr() != ERROR_NO_MORE_ENTRIES))
  421.         {
  422.             ShowRequester("ExAll failed abnormally");//: %ld.", IoErr());
  423.             break;
  424.         }
  425.  
  426.         if (myexallctrl->eac_Entries)
  427.         {
  428.           eadptr=ExAllBuf;
  429.  
  430.           while (eadptr)
  431.           {
  432.             if (eadptr->ed_Type < 0)  /* make sure it is a file, not a directory, see end of dos/dosextens.h */
  433.             {
  434.               strcpy(filename, eadptr->ed_Name);
  435.  
  436.               /* truncate the filename if it is an icon, ie. remove the ".info" */
  437.               if (!Stricmp(filename+strlen(filename)-5,".info"))
  438.                 filename[strlen(filename) - 5] = NULL;  /* take the .info off of the string */
  439.               else
  440.                 filename[strlen(filename)] = NULL;  /* take the .info off of the string */
  441.  
  442.               /* See if the file is already in the list */
  443.               if (!Finditem(filename))
  444.               {
  445.                 if (Stricmp(filename,"WBStartup+"))  /* Make sure we don't recursively run ourself */
  446.                 {
  447.                   strcpy(pathname,directory);
  448.                   AddPart(pathname, filename, 500);
  449.  
  450.                   AddFileToList(memPool,pathname,type);
  451.                 }
  452.               }
  453.             }
  454.             eadptr=eadptr->ed_Next;
  455.           }
  456.         }
  457.  
  458.       } while (more);
  459.  
  460.       FreeDosObject(DOS_EXALLCONTROL,myexallctrl);
  461.     }
  462.     else
  463.       ShowRequester("Not enough memory for ExAllControl.");
  464.     UnLock(mylock);
  465.   }
  466.   else
  467.     ShowRequester(GetString(STRCouldntLockDir));
  468. }
  469.  
  470. BOOL Finditem (char *name)
  471. {
  472.     LONG entry;
  473.     struct WBSPNode *node;
  474.     BOOL found=FALSE;
  475.     for (entry=0;;entry++)
  476.     {
  477.           DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  478.           if (!node)
  479.             break;
  480.           if (!(stricmp(node->wbsp_name,name)))
  481.               {
  482.         found=TRUE;
  483.         break;
  484.           }
  485.         }
  486.         return(found);
  487. }
  488.  
  489.  
  490. struct WBSPNode *AddFileToList(APTR memPool, char *pathname, UBYTE type)
  491. {
  492.   /* pathname should be like:  ram:t/myfile */
  493.   struct WBSPNode *node;             /* hold the filenames and proiority for the List */
  494.   struct DiskObject *diskobj;        /* Pointer to the icon info */
  495.   char *toolstring;                  /* Pointer to a tooltype string */
  496.   char *filenameptr;
  497.  
  498.   filenameptr=FilePart(pathname);
  499.  
  500.   if (diskobj=GetDiskObjectNew(pathname))
  501.   {
  502.     if ((diskobj->do_Type==WBPROJECT) || (diskobj->do_Type==WBTOOL))  /* Make sure we got an icon that isn't a drawer icon */
  503.     {
  504.       if (node=(struct WBSPNode *)AllocPooled(memPool,sizeof(struct WBSPNode)))
  505.       {
  506.         if (node->wbsp_name=(char *)AllocPooled(memPool, strlen(filenameptr)+1))
  507.         {
  508.           strcpy(node->wbsp_name, filenameptr);
  509.           if (toolstring=FindToolType(diskobj->do_ToolTypes,"STARTPRI"))
  510.             node->wbsp_pri = node->Original_Priority = atoi((char *)toolstring);
  511.           else
  512.             node->wbsp_pri = node->Original_Priority = 0;
  513.           node->wbsp_type = node->Original_Type = type;  /* EXECUTE or STORAGE */
  514.       DoMethod(lsobj,MUIM_NList_InsertSingle,node,MUIV_NList_Insert_Sorted);
  515.           prefs.NumPrograms++;
  516.         }
  517.       }
  518.     }
  519.     FreeDiskObject(diskobj);
  520.   }
  521.   return(node);
  522. }
  523.  
  524.  
  525.  
  526. void GetArguments(int argc, char **argv)
  527. {
  528.   UBYTE **ttypes;
  529.  
  530.   ttypes = ArgArrayInit(argc,argv);
  531.   strcpy(prefs.ExecutePath , ArgString(ttypes,"ENABLEDPATH","SYS:WBStartup/WBStartup (Enabled)"));
  532.   strcpy(prefs.StoragePath , ArgString(ttypes,"DISABLEDPATH","SYS:WBStartup/WBStartup (Disabled)"));
  533.   prefs.Alphabetize = ((FindToolType(ttypes,"ALPHABETIZE")) ? TRUE : FALSE);
  534.   ArgArrayDone();
  535. }
  536.  
  537. void ProcessEvents(APTR groupPool)
  538. {
  539.   ULONG signals;
  540.   BOOL LOOP;
  541.  
  542.   struct WBSPNode *node;
  543.   struct GroupNode *groupnode;  /* ptr to a node in the group list */
  544.   char *groupname;
  545.   struct Screen *WScreen;
  546.  
  547.   BOOL GroupsModified=FALSE;
  548.  
  549.   ULONG returnid,entry,column,menuitemid,newpri,forcequit;
  550.  
  551.   //Open the GUI and process user actions
  552.   SetAttrs(winobj,MUIA_Window_Open,TRUE,TAG_DONE);
  553.   signals=0;
  554.   LOOP=TRUE;
  555.   while (LOOP)
  556.   {
  557.       if (signals)
  558.           signals=Wait(signals);
  559.       returnid=DoMethod(appobj,MUIM_Application_NewInput,&signals);
  560.       switch (returnid)
  561.       {
  562.           case MUIV_Application_ReturnID_Quit:
  563.               LOOP=FALSE;
  564.             break;
  565.           case 1:
  566.               GetAttr(MUIA_NList_EntryClick,lsobj,&entry);
  567.               GetAttr(MUIA_NList_ClickColumn,lsobj,&column);
  568.             DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  569.             switch (column)
  570.             {
  571.                 case 0:
  572.                     if (node->wbsp_type)
  573.                                           node->wbsp_type = STORAGE;
  574.                                     else
  575.                                         node->wbsp_type = EXECUTE;
  576.                       DoMethod(lsobj,MUIM_NList_Redraw,entry);
  577.                 break;
  578.                 case 2:
  579.                     GetPriority(node->wbsp_pri);
  580.                 break;
  581.             }
  582.           break;
  583.           case 2:
  584.               GetAttr(MUIA_Application_MenuAction,appobj,&menuitemid);
  585.             switch(menuitemid)
  586.                         {
  587.                           case SAVE_MENU:
  588.                 SetAttrs(winobj,MUIA_Window_Sleep,TRUE,MUIA_Window_Title,GetString(STRSaving),TAG_DONE);
  589.                             SaveChanges();
  590.                             LOOP=FALSE;
  591.                             break;
  592.                           case ABOUT_MENU:
  593.                             {
  594.                               SetAttrs(winobj,MUIA_Window_Sleep,TRUE,TAG_DONE);
  595.                   MUI_Request(appobj,winobj,0,"WBStartup+Prefs",GetString(STROk),GetString(STRAbout),VERSION,COPYRIGHT,DATETEXT);
  596.                               SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  597.                             }
  598.                             break;
  599.                           case QUIT_MENU:
  600.                             LOOP=FALSE;
  601.                             break;
  602.                           case RESTORE_MENU:
  603.                             RestoreTypes();
  604.                             break;
  605.                           case PROGRAMINFO_MENU:
  606.                 SetAttrs(winobj,MUIA_Window_Sleep,TRUE,TAG_DONE);
  607.                 GetAttr(MUIA_NList_Active,lsobj,(ULONG *)&node);
  608.                 if ((ULONG)node!=MUIV_NList_Active_Off)
  609.                             {
  610.                 GetAttr(MUIA_Window_Screen,winobj,(ULONG *)&WScreen);
  611.                                 ShowWBIconRequester(node,WScreen);
  612.                             }
  613.                             else
  614.                               ShowRequester("You must first select a program!");
  615.                 SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  616.                             break;
  617.                           case SORTALPHABETICALLY_MENU:
  618.                             prefs.Alphabetize = TRUE;
  619.                 SortList();
  620. //                DoMethod(lsobj,MUIM_NList_Sort);
  621.                             break;
  622.                           case SORTPRIORITY_MENU:
  623.                             prefs.Alphabetize = FALSE;
  624.                 SortList();
  625. //                DoMethod(lsobj,MUIM_NList_Sort);
  626.                             break;
  627.                           case SELECTALL_MENU:
  628.                             for (entry=0;;entry++)
  629.                 {
  630.                   DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  631.                   if (!node)
  632.                     break;
  633.                               node->wbsp_type = EXECUTE;
  634.                     }
  635.                     DoMethod(lsobj,MUIM_NList_Redraw,MUIV_NList_Redraw_All);
  636.                             break;
  637.                           case SELECTNONE_MENU:
  638.                             for (entry=0;;entry++)
  639.                 {
  640.                   DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  641.                   if (!node)
  642.                     break;
  643.                               node->wbsp_type = STORAGE;
  644.                     }
  645.                     DoMethod(lsobj,MUIM_NList_Redraw,MUIV_NList_Redraw_All);
  646.                             break;
  647.                           case SELECTTOGGLE_MENU:
  648.                             for (entry=0;;entry++)
  649.                 {
  650.                   DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  651.                   if (!node)
  652.                     break;
  653.                   if (node->wbsp_type == EXECUTE)
  654.                                 node->wbsp_type = STORAGE;
  655.                               else
  656.                                 node->wbsp_type = EXECUTE;
  657.                     }
  658.                     DoMethod(lsobj,MUIM_NList_Redraw,MUIV_NList_Redraw_All);
  659.                             break;
  660.                           case CREATEGROUP_MENU:
  661.                 GetStringWindow(GetString(STRGroupName),30);
  662.                             break;
  663.                           case DELETEGROUP_MENU:
  664.                 ChooseGroup("Delete Group");
  665.                             break;
  666.                           case MODIFYGROUP_MENU:
  667.                 ChooseGroup("Modify Group");
  668.                             break;
  669.                           case SELECTGROUP_MENU:
  670.                 ChooseGroup("Select Group");
  671.                             break;
  672.                         }
  673.           break;
  674.           case 3:
  675.             SetAttrs(winobj,MUIA_Window_Sleep,TRUE,MUIA_Window_Title,GetString(STRSaving),TAG_DONE);
  676.                         SaveChanges();
  677.                         LOOP=FALSE;
  678.           break;
  679.           case 4:
  680.               GetAttr(MUIA_Slider_Level,sliderobj,&newpri);
  681.             SetAttrs(pwinobj,MUIA_Window_Open,FALSE,TAG_DONE);
  682.             DoMethod(appobj,OM_REMMEMBER,pwinobj);
  683.             MUI_DisposeObject(swinobj);
  684.               node->wbsp_pri=(int)newpri;
  685.             DoMethod(lsobj,MUIM_NList_Redraw,entry);
  686.             DoMethod(lsobj,MUIM_NList_Sort);
  687.             SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  688.           break;
  689.           case 5:
  690.               GetAttr(MUIA_String_Contents,strobj,(ULONG *)&groupname);
  691.                         if (groupname[0])
  692.                         {
  693.                           CreateGroup(groupname, groupPool);
  694.                           GroupsModified=TRUE;
  695.                         }
  696.           case 6:
  697.               SetAttrs(swinobj,MUIA_Window_Open,FALSE,TAG_DONE);
  698.             DoMethod(appobj,OM_REMMEMBER,swinobj);
  699.             MUI_DisposeObject(swinobj);
  700.             SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  701.           break;
  702.           case 7:
  703.               SetAttrs(gwinobj,MUIA_Window_Open,FALSE,TAG_DONE);
  704.             SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  705.           break;
  706.           case 8:
  707.               SetAttrs(gwinobj,MUIA_Window_Open,FALSE,TAG_DONE);
  708.             switch (menuitemid)
  709.                 {
  710.                     case DELETEGROUP_MENU:
  711.                           DeleteGroup(groupPool);
  712.                         GroupsModified=TRUE;
  713.                     break;
  714.                     case SELECTGROUP_MENU:
  715.                         DoMethod(glsobj,MUIM_NList_GetEntry,MUIV_NList_GetEntry_Active,&groupnode);
  716.                         SelectGroup(&(groupnode->enabled));
  717.                         DoMethod(lsobj,MUIM_NList_Redraw,MUIV_NList_Redraw_All);
  718.                     break;
  719.                     case MODIFYGROUP_MENU:
  720.                         DoMethod(glsobj,MUIM_NList_GetEntry,MUIV_NList_GetEntry_Active,&groupnode);
  721.                         strcpy(groupname,groupnode->group_name);
  722.                         DeleteGroup(groupPool);
  723.                         CreateGroup(groupname,groupPool);
  724.                         GroupsModified=TRUE;
  725.                     break;
  726.                 }
  727.             SetAttrs(winobj,MUIA_Window_Sleep,FALSE,TAG_DONE);
  728.           break;
  729.           case 9:
  730.                 prefs.Alphabetize = TRUE;
  731.             SortList();
  732. //            DoMethod(lsobj,MUIM_NList_Sort);
  733.                   break;
  734.                   case 10:
  735.                         prefs.Alphabetize = FALSE;
  736.             SortList();
  737. //            DoMethod(lsobj,MUIM_NList_Sort);
  738.           break;
  739.       }
  740.   }
  741.   GetAttr(MUIA_Application_ForceQuit,appobj,&forcequit);
  742.   /* Notify user if groups were modified. */
  743.   if (GroupsModified && !forcequit)
  744.     if(ShowGroupsRequester())
  745.       SaveGroups();
  746. }
  747.  
  748. void SortList()
  749. {
  750.     DoMethod(lsobj,MUIM_NList_Sort);
  751.     if (prefs.Alphabetize)
  752.         SetAttrs(lsobj,MUIA_NList_TitleMark,MUIV_NList_TitleMark_Down|1);
  753.     else
  754.         SetAttrs(lsobj,MUIA_NList_TitleMark,MUIV_NList_TitleMark_Down|2);
  755. }
  756.  
  757. /*****************************/
  758. /* Process App Window events */
  759. /*****************************/
  760. void __asm __saveds ProcessAppMsg(register __a1 ULONG *argsptr)
  761. {
  762.   struct AppMessage *amsg;
  763.   struct WBArg *argptr;
  764.   LONG argnum;
  765.   char *sourcename,*destname;
  766.   int flags=WBSP_ENABLED;
  767.  
  768.   SetAttrs(winobj,MUIA_Window_Sleep,TRUE,TAG_DONE);
  769.   amsg=(struct AppMessage *)*argsptr;
  770.    if (SameLock(amsg->am_ArgList->wa_Lock,prefs.EnabledDirLock)==LOCK_SAME_VOLUME)
  771.     flags |= WBSP_MOVE;
  772.   flags = CopyWindow(flags);
  773.    if (!(flags & WBSP_CANCEL))
  774.   {
  775.     SetAttrs(winobj,MUIA_Window_Title,GetString(STRCopyingFiles),TAG_DONE);
  776.     argptr = amsg->am_ArgList;
  777.     for (argnum=0; argnum < amsg->am_NumArgs; argnum++)
  778.     {
  779.        if (sourcename=(char *)AllocVec(500,MEMF_PUBLIC))
  780.       {
  781.         int destlen;
  782.          NameFromLock(argptr->wa_Lock,sourcename,500);
  783.         AddPart(sourcename,argptr->wa_Name,500);
  784.          if (flags & WBSP_ENABLED)
  785.           destlen = strlen(prefs.ExecutePath)+strlen(argptr->wa_Name)+2;
  786.         else
  787.           destlen = strlen(prefs.StoragePath)+strlen(argptr->wa_Name)+2;
  788.          if (destname=(char *)AllocVec(destlen,MEMF_PUBLIC))
  789.         {
  790.           strcpy(destname,(flags & WBSP_ENABLED) ? prefs.ExecutePath : prefs.StoragePath);
  791.           AddPart(destname,argptr->wa_Name,500);
  792.            /* Copy or Move files */
  793.           if (flags & WBSP_MOVE)
  794.           {
  795.             if (SameLock(amsg->am_ArgList->wa_Lock,prefs.EnabledDirLock)==LOCK_SAME_VOLUME)
  796.             {
  797.               /* Move files on same device */
  798.               struct DiskObject *diskobj;
  799.                Rename(sourcename,destname);
  800.               if (diskobj=GetDiskObject(sourcename))
  801.               {
  802.                 diskobj->do_CurrentX = diskobj->do_CurrentY = NO_ICON_POSITION;
  803.                 if (PutDiskObject(destname,diskobj))
  804.                   DeleteDiskObject(sourcename);
  805.                 FreeDiskObject(diskobj);
  806.               }
  807.             }
  808.             else
  809.               /* Move files on different devices */
  810.               if (CopyFile(sourcename,destname))
  811.               {
  812.                 DeleteFile(sourcename);
  813.                 DeleteDiskObject(sourcename);
  814.               }
  815.           }
  816.           else
  817.             CopyFile(sourcename,destname);
  818.            /* Add file to list */
  819.           AddFileToList(prefs.filenamePool,destname, (flags & WBSP_ENABLED) ? EXECUTE : STORAGE);
  820.           FreeVec(destname);
  821.         }
  822.         FreeVec(sourcename);
  823.         argptr++;
  824.       }
  825.     }
  826.   }
  827.   SetAttrs(winobj,MUIA_Window_Sleep,FALSE,MUIA_Window_Title,"WBStartup+ Prefs",TAG_DONE);
  828. }
  829.  
  830. void ShowRequester(STRPTR RequesterText)
  831. {
  832.   MUI_Request(appobj,winobj,0,"WBStartup+Prefs",GetString(STROk),RequesterText,0);
  833. }
  834.  
  835. void RestoreTypes(void)
  836. {
  837.   struct WBSPNode *node;
  838.   LONG entry;
  839.  
  840.   for (entry=0;;entry++)
  841.   {
  842.     DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  843.     if (!node)
  844.       break;      
  845.     node->wbsp_type = node->Original_Type;
  846.     node->wbsp_pri = node->Original_Priority;
  847.   }
  848.   DoMethod(lsobj,MUIM_NList_Sort);
  849.   DoMethod(lsobj,MUIM_NList_Redraw,MUIV_NList_Redraw_All);
  850. }
  851.  
  852. void SaveChanges(void)
  853. {
  854.   struct WBSPNode *node;
  855.   char pathname1[500];
  856.   char icon1[500];
  857.   char pathname2[500];
  858.   char icon2[500];
  859.   BOOL DifferentVolumes = FALSE;  // TRUE when the Enabled and Disabled paths are on different volumes
  860.   LONG entry;
  861.  
  862.   if (SameLock(prefs.EnabledDirLock, prefs.DisabledDirLock)==LOCK_DIFFERENT)
  863.     DifferentVolumes = TRUE;
  864.  
  865.   for (entry=0;;entry++)
  866.   {
  867.     DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  868.     if (!node)
  869.           break;
  870.       /* Change STARTPRI tooltypes */
  871.       if (node->wbsp_pri != node->Original_Priority)
  872.       {
  873.         if (node->Original_Type == EXECUTE)
  874.           strcpy(pathname1,prefs.ExecutePath);
  875.         else
  876.           strcpy(pathname1,prefs.StoragePath);
  877.         AddPart(pathname1,node->wbsp_name,1100-1);
  878.         ChangePriTooltype(pathname1,node->wbsp_pri);
  879.       }
  880.   
  881.       /* Move files */
  882.       if (node->wbsp_type != node->Original_Type)
  883.       {
  884.         strcpy(pathname1,prefs.ExecutePath);
  885.         AddPart(pathname1,node->wbsp_name,1100-1);
  886.         sprintf(icon1, "%s.info",pathname1 );
  887.   
  888.         strcpy(pathname2,prefs.StoragePath);
  889.         AddPart(pathname2,node->wbsp_name,1100-1);
  890.         sprintf(icon2, "%s.info",pathname2 );
  891.  
  892.         if (node->wbsp_type == STORAGE)
  893.         {
  894.           if (DifferentVolumes)
  895.           {
  896.             /* Move files on different volumes */
  897.             if (CopyFile(pathname1,pathname2))
  898.             {
  899.               DeleteFile(pathname1);
  900.               DeleteDiskObject(pathname1);
  901.             }
  902.           }
  903.           else
  904.           {
  905.             /* Move files on same volumes */
  906.             Rename(pathname1,pathname2);
  907.             Rename(icon1,icon2);
  908.           }
  909.         }
  910.         else
  911.         {
  912.           if (DifferentVolumes)
  913.           {
  914.             /* Move files on different volumes */
  915.             if (CopyFile(pathname2,pathname1))
  916.             {
  917.               DeleteFile(pathname2);
  918.               DeleteDiskObject(pathname2);
  919.             }
  920.           }
  921.           else
  922.           {
  923.             /* Move files on same volumes */
  924.             Rename(pathname2,pathname1);
  925.             Rename(icon2,icon1);
  926.           }
  927.         }
  928.       }
  929.   }
  930. }
  931.  
  932.  
  933. BOOL ChangePriTooltype(char *filename, BYTE pri)
  934. {
  935.   struct DiskObject *dobj;
  936.   char **oldtooltypes;
  937.   char **newtooltypes;
  938.   BOOL success=FALSE;
  939.   char pristr[18];
  940.   int numberoftooltypes=1; /* set it to 1 since we need one for the final NULL */
  941.   char **ptr, **newptr;
  942.   BOOL wrotepri=FALSE;
  943.  
  944.   if (dobj=GetDiskObjectNew(filename))
  945.   {
  946.     /* count tooltypes */
  947.     for (ptr = dobj->do_ToolTypes; *ptr; ptr++)
  948.       numberoftooltypes++;
  949.     if (!FindToolType(dobj->do_ToolTypes,"STARTPRI"))
  950.       numberoftooltypes++;
  951.  
  952.     /* Allocate new tooltype pointer list */
  953.     if (newtooltypes = AllocVec(numberoftooltypes * sizeof(char *),MEMF_PUBLIC))
  954.     {
  955.       sprintf(pristr,"STARTPRI=%ld",(long)pri);
  956.  
  957.       /* Copy tooltype pointers */
  958.       newptr=newtooltypes;
  959.       for (ptr = dobj->do_ToolTypes; *ptr; ptr++)
  960.       {
  961.         if (strncmp(*ptr,"STARTPRI",8))
  962.           *newptr = *ptr;  /* copy argument */
  963.         else
  964.         {
  965.           if (!wrotepri)
  966.           {
  967.             *newptr = &pristr[0];
  968.             wrotepri=TRUE;
  969.           }
  970.           else
  971.             newptr--;
  972.         }
  973.         newptr++;
  974.       }
  975.       if (!wrotepri)
  976.         *newptr++ = &pristr[0];
  977.       *newptr = NULL;
  978.  
  979.       oldtooltypes = dobj->do_ToolTypes;
  980.       dobj->do_ToolTypes = newtooltypes;
  981.  
  982.       success = PutDiskObject(filename, dobj);
  983.  
  984.       dobj->do_ToolTypes = oldtooltypes;
  985.  
  986.       FreeVec(newtooltypes);
  987.     }
  988.     FreeDiskObject(dobj);
  989.   }
  990.  
  991.   return(success);
  992. }
  993.  
  994. void ShowWBIconRequester(struct WBSPNode *node,struct Screen *scr)
  995. {
  996.   BPTR lock;
  997.   char *dirname;
  998.  
  999.   if (node->Original_Type == EXECUTE)
  1000.     dirname = prefs.ExecutePath;
  1001.   else
  1002.     dirname = prefs.StoragePath;
  1003.  
  1004.   if (lock = Lock(dirname,SHARED_LOCK))
  1005.   {
  1006.     WBInfo(lock, node->wbsp_name, scr);
  1007.     UnLock(lock);
  1008.   }
  1009. }
  1010.  
  1011. void SaveGroups()
  1012. {
  1013.   BPTR file;
  1014.   struct GroupNode *groupnode;
  1015.   struct Node *node;
  1016.   LONG entry;
  1017.  
  1018.   if (file = Open(PREFSFILE,MODE_NEWFILE))
  1019.   {
  1020.     for (entry=0;;entry++)
  1021.     {
  1022.       DoMethod(glsobj,MUIM_NList_GetEntry,entry,&groupnode);
  1023.       if (!groupnode)
  1024.         break;
  1025. /*    for (groupnode=(struct GroupNode *)list->lh_Head ; groupnode->group_node.ln_Succ ; groupnode = (struct GroupNode *)groupnode->group_node.ln_Succ)
  1026.     {*/
  1027.       FPutC(file,'@');
  1028.       FPuts(file, groupnode->group_name);
  1029.       FPutC(file,10);  /* 10 = NEWLINE */
  1030.       for (node = groupnode->enabled.lh_Head ; node->ln_Succ ; node = node->ln_Succ)
  1031.       {
  1032.         FPuts(file, node->ln_Name);
  1033.         FPutC(file,10);
  1034.       }
  1035.     }
  1036.     Close(file);
  1037.   }
  1038. }
  1039.  
  1040. void ReadGroups(APTR memPool)
  1041. {
  1042.   BPTR file;
  1043.   struct GroupNode *groupnode;
  1044.   struct Node *node;
  1045.   char buffer[40];
  1046.  
  1047. //  NewList(list);
  1048.   if (file = Open(PREFSFILE,MODE_OLDFILE))
  1049.   {
  1050.     while (FGets(file,buffer,40))
  1051.     {
  1052.       buffer[strlen(buffer)-1]=NULL; /* Remove the NEWLINE character from the end */
  1053.       if (buffer[0] == '@')
  1054.       {
  1055.         if (groupnode=(struct GroupNode *)AllocPooled(memPool,sizeof(struct GroupNode)))
  1056.         {
  1057.           if (groupnode->group_name=(char *)AllocPooled(memPool,strlen(buffer+1)+1))
  1058.           {
  1059.             strcpy(groupnode->group_name,buffer+1);
  1060.             NewList(&groupnode->enabled);
  1061. //            AddTail(list,groupnode);
  1062.         DoMethod(glsobj,MUIM_NList_InsertSingle,groupnode,MUIV_NList_Insert_Bottom);
  1063.           }
  1064.           else
  1065.             FreePooled(memPool,groupnode,sizeof(struct GroupNode));
  1066.         }
  1067.       }
  1068.       else  /* Add to group */
  1069.       {
  1070.         if (node=(struct Node *)AllocPooled(memPool,sizeof(struct Node)))
  1071.         {
  1072.           if (node->ln_Name=(char *)AllocPooled(memPool,strlen(buffer)+1))
  1073.           {
  1074.             strcpy(node->ln_Name,buffer);
  1075.             AddTail(&groupnode->enabled,node);
  1076.           }
  1077.           else
  1078.             FreePooled(memPool,node,sizeof(struct Node));
  1079.         }
  1080.       }
  1081.     }
  1082.     Close(file);
  1083.   }
  1084. }
  1085.  
  1086. void CreateGroup(char *groupname, APTR memPool)
  1087. {
  1088.   struct GroupNode *groupnode;
  1089.   struct Node *node;
  1090.   struct WBSPNode *wbspnode;
  1091.   ULONG entry;
  1092.  
  1093.   if (groupnode=(struct GroupNode *)AllocPooled(memPool,sizeof(struct GroupNode)))
  1094.   {
  1095.     if (groupnode->group_name=(char *)AllocPooled(memPool,strlen(groupname)+1))
  1096.     {
  1097.       strcpy(groupnode->group_name,groupname);
  1098.       NewList(&groupnode->enabled);
  1099.  
  1100.       for (entry=0;;entry++)
  1101.       {
  1102.     DoMethod(lsobj,MUIM_NList_GetEntry,entry,&wbspnode);
  1103.     if (!wbspnode)
  1104.       break;
  1105.         if (wbspnode->wbsp_type == EXECUTE)
  1106.         {
  1107.           if (node=(struct Node *)AllocPooled(memPool,sizeof(struct Node)))
  1108.           {
  1109.             if (node->ln_Name=(char *)AllocPooled(memPool,strlen(wbspnode->wbsp_name)+1))
  1110.             {
  1111.               strcpy(node->ln_Name,wbspnode->wbsp_name);
  1112.               AddTail(&groupnode->enabled,node);
  1113.             }
  1114.             else
  1115.               FreePooled(memPool,node,sizeof(struct Node));
  1116.           }
  1117.         }
  1118.     }
  1119.     DoMethod(glsobj,MUIM_NList_InsertSingle,groupnode,MUIV_NList_Insert_Bottom);
  1120.     }
  1121.     else
  1122.       FreePooled(memPool,groupnode,sizeof(struct GroupNode));
  1123.   }
  1124. }
  1125.  
  1126. void SelectGroup(struct List *subgrouplist)
  1127. {
  1128.   struct WBSPNode *node;
  1129.   ULONG entry;
  1130.  
  1131.   for (entry=0;;entry++)
  1132.   {
  1133.       DoMethod(lsobj,MUIM_NList_GetEntry,entry,&node);
  1134.       if (!node)
  1135.         break;
  1136.       if (FindName(subgrouplist,node->wbsp_name))
  1137.         node->wbsp_type = EXECUTE;
  1138.       else
  1139.         node->wbsp_type = STORAGE;
  1140.   }
  1141. }
  1142.  
  1143. void DeleteGroup(APTR memPool)
  1144. {
  1145.   struct GroupNode *node;
  1146.   struct Node *worknode;
  1147.   struct Node *nextnode;
  1148.  
  1149.     DoMethod(glsobj,MUIM_NList_GetEntry,MUIV_NList_GetEntry_Active,&node);
  1150.     DoMethod(glsobj,MUIM_NList_Remove,MUIV_NList_Remove_Active);
  1151.     FreePooled(memPool,node->group_name,strlen(node->group_name)+1);
  1152.  
  1153.     worknode=node->enabled.lh_Head;
  1154.     while (nextnode = worknode->ln_Succ)
  1155.     {
  1156.       FreePooled(memPool,worknode->ln_Name,strlen(worknode->ln_Name)+1);
  1157.       FreePooled(memPool,worknode,sizeof(struct Node));
  1158.       worknode=nextnode;
  1159.     }
  1160.  
  1161.     FreePooled(memPool,node,sizeof(struct GroupNode));
  1162. }
  1163.  
  1164. BOOL ShowGroupsRequester(void)
  1165. {
  1166.   return((BOOL)MUI_Request(appobj,winobj,0,"WBStartup+Prefs",GetString(STRSaveNoGadget),GetString(STRAskSaveGroups),0));
  1167. }
  1168.  
  1169.  
  1170. BOOL CopyFile(char *source,char *dest)
  1171. {
  1172.   /* source and dest should include the path and filename */
  1173.   BPTR infile,outfile;
  1174.   STRPTR buf=NULL;
  1175.   long x;
  1176.   struct DiskObject *diskobj;
  1177.   BOOL success=TRUE;
  1178.   //const long bufsize=512;
  1179.   //long numbuf=200;
  1180.   const long bufsize=1;
  1181.   long numbuf=200*512;
  1182.  
  1183.   /* Allocate the buffer used to copy the file */
  1184.   while ((buf==NULL) && (numbuf>0))
  1185.     if (!(buf=(STRPTR)AllocVec(bufsize*numbuf,MEMF_PUBLIC)))
  1186. //      numbuf-=10;
  1187.       numbuf/=2;
  1188.  
  1189.   /* Copy File */
  1190.   if (buf)
  1191.   {
  1192.     if (infile=Open(source,MODE_OLDFILE))
  1193.     {
  1194.       if (outfile=Open(dest,MODE_NEWFILE))
  1195.       {
  1196.         SetVBuf(outfile,NULL,BUF_FULL,bufsize*numbuf);
  1197.         do {
  1198.           x=FRead(infile,buf,bufsize,numbuf);
  1199.           FWrite(outfile,buf,bufsize,x);
  1200.         } while(x);
  1201.  
  1202.         Close(infile);
  1203.       }
  1204.       else
  1205.         success=FALSE;
  1206.       Close(outfile);
  1207.     }
  1208.     FreeVec(buf);
  1209.   }
  1210.   else
  1211.     success=FALSE;
  1212.  
  1213.   /* Copy Icon */
  1214.   if (diskobj=GetDiskObject(source))
  1215.   {
  1216.     diskobj->do_CurrentX = diskobj->do_CurrentY = NO_ICON_POSITION;
  1217.     if (!PutDiskObject(dest,diskobj))
  1218.       success=FALSE;
  1219.     FreeDiskObject(diskobj);
  1220.   }
  1221.  
  1222.   return(success);
  1223. }
  1224.